package x.y.z;

public class Interview_1_6_StringCompression {
    public String compressString(String S) {
        StringBuilder sb = new StringBuilder();
        int count = 0;
        for (int i = 0; i < S.length(); i++) {
            count++;
            if (i + 1 >= S.length() || S.charAt(i) != S.charAt(i + 1)) {
                sb.append(S.charAt(i));
                sb.append(count);
                count = 0;
            }
        }
        return sb.length() >= S.length() ? S : sb.toString();
    }
}
